<template>
	<view>
		<image src="../../static/login/top3.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">专业代驾 服务第一</text>
		</view>
		<button class="btn" @tap="wxLogin()">司机登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>


export default {
	data() {
		return {};
	},
	methods: {
    toRegisterPage(){
      //在起始页面跳转到test.vue页面并传递参数
      uni.navigateTo({
        url: '../register/register'
      });
    },
    wxLogin(){
      let _this = this;
      wx.login({
        success: function (res) {
          if (res.code) {
            //发起网络请求
            _this.code = res.code;
            console.log(res.code)
            //发起微信注册请求
            _this.get("/uaa/manager/login/login/"+res.code+"/18723000000",function(res){
              console.log(res)
              let {success,code,message,data} = res.data;
              if(success){
                //保存登录信息
                uni.setStorageSync("token",data.token);
                uni.setStorageSync("avatar",data.avatar);
                uni.setStorageSync("nickName",data.nickName);
                uni.setStorageSync("phone",data.phone);
                uni.setStorageSync("userId",data.id);

                uni.showToast({ icon:"success", title:"登录成功" })
                //跳转页面
                //跳转工作台页面
                setTimeout(()=>{
                  uni.switchTab({
                    url:"/pages/workbench/workbench"
                  })
                },2000)
              }
            });
          } else {
            console.log('登录失败！' + res.errMsg)
          }
        }
      });
    }
	},
	onLoad: function() {
	}
};
</script>

<style lang="less">
@import url('login.less');
</style>
